import random
import string
from optparse import OptionParser

numbers = '0123456789'
symbols = '!#$%&()*+-/:;<=>?@[\]^_{|}~'
lower = 'abcdefghijklmnopqrstuvwxyz'
upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
items = numbers + symbols + lower + upper

def gen_key(length):
	if length < 8:
		length = 8

	keys = []
	keys.append(random.choice(numbers))
	keys.append(random.choice(symbols))
	keys.append(random.choice(lower))
	keys.append(random.choice(upper))
	for i in range(length - 4):
		keys.append(random.choice(items))
	random.shuffle(keys)
	keys = string.join(keys)	
	keys = keys.replace(' ', '')
	
	print keys


def main():
	parser = OptionParser()
	parser.add_option("-l", "--length", type="int", dest="length", 
					  default=16, help="set length of key")
	parser.add_option("-n", "--number", type="int", dest="number", 
					  default=1, help="set number of keys")
	(options, args) = parser.parse_args()
	key_len = options.length
	key_num = options.number

	for i in range(key_num):
		gen_key(key_len)


if __name__ == "__main__":
    main()

